home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / midas060 / src / postproc.asm < prev    next >
Encoding:
Assembly Source File  |  1997-01-16  |  12.3 KB  |  467 lines

  1. ;*      POSTPROC.ASM
  2. ;*
  3. ;* Post-processing routines common for all mixing Sound Devices
  4. ;*
  5. ;* $Id: postproc.asm,v 1.3 1997/01/16 18:41:59 pekangas Exp $
  6. ;*
  7. ;* Copyright 1996,1997 Housemarque Inc.
  8. ;*
  9. ;* This file is part of the MIDAS Sound System, and may only be
  10. ;* used, modified and distributed under the terms of the MIDAS
  11. ;* Sound System license, LICENSE.TXT. By continuing to use,
  12. ;* modify or distribute this file you indicate that you have
  13. ;* read the license and understand and accept it fully.
  14. ;*
  15.  
  16. IDEAL
  17. P386
  18.  
  19. INCLUDE "lang.inc"
  20.  
  21. MIX8BITS = 12                           ; number of bits of accuracy in
  22.                                         ; mixing for 8-bit output
  23.  
  24.  
  25.  
  26. ;/***************************************************************************\
  27. ;*
  28. ;* Macro:    NumLabel lblname, lblnum
  29. ;*
  30. ;* Description: Creates a numbered label in the source, format _namenum
  31. ;*              (eg. _table1)
  32. ;*
  33. ;* Input:    lblname     name for the label
  34. ;*        lblnum        number for the label
  35. ;*
  36. ;\***************************************************************************/
  37.  
  38. MACRO    NumLabel lblname, lblnum
  39. _&lblname&lblnum:
  40. ENDM
  41.  
  42.  
  43.  
  44. ;/***************************************************************************\
  45. ;*
  46. ;* Macro:    JmpTable lblname, lblcount
  47. ;*
  48. ;* Description: Creates a jump offset table in the source. The table consists
  49. ;*        of near offsets of labels _lblname0 - _lblnameX
  50. ;*
  51. ;* Input:    lblname     name of labels to be used for the table
  52. ;*        lblcount    number of labels
  53. ;*
  54. ;\***************************************************************************/
  55.  
  56. MACRO   defoffs lblname, lblnum
  57. IFDEF __16__
  58.     DW    offset _&lblname&lblnum
  59. ELSE
  60.         DD      offset _&lblname&lblnum
  61. ENDIF
  62. ENDM
  63.  
  64. MACRO    JmpTable lblname, lblcount
  65. numb = 0
  66. REPT    lblcount
  67.         defoffs lblname, %numb
  68. numb = numb + 1
  69. ENDM
  70. ENDM
  71.  
  72.  
  73. DATASEG
  74.  
  75. oldValue        DD      0
  76.  
  77.  
  78. CODESEG
  79.  
  80.  
  81.  
  82. GLOBAL  LANG pp16Mono : _funct
  83. GLOBAL  LANG pp8Mono : _funct
  84. GLOBAL  LANG pp16Stereo : _funct
  85. GLOBAL  LANG pp8Stereo : _funct
  86.  
  87.  
  88.  
  89.  
  90. ;IFDEF __32__
  91. ;LABEL   pp16Jump        _int
  92. ;JmpTable pp16, 17
  93. ;ENDIF
  94.  
  95. ;/***************************************************************************\
  96. ;*
  97. ;* Function:    unsigned pp16Mono(unsigned numElements, uchar *bufStart,
  98. ;*                  unsigned mixPos, unsigned *mixBuffer, uchar *ppTable);
  99. ;*
  100. ;* Description: 16-bit mono post-processing routine
  101. ;*
  102. ;* Input:       unsigned numElements    number of elements to process
  103. ;*                                       (guaranteed to be even)
  104. ;*              uchar *bufStart         pointer to start of DMA buffer
  105. ;*              unsigned mixPos         mixing position in DMA buffer
  106. ;*              unsigned *mixBuffer     pointer to source mixing buffer
  107. ;*              uchar *ppTable          post-processing table
  108. ;*
  109. ;* Returns:     New mixing position in DMA buffer. Can not fail.
  110. ;*
  111. ;\***************************************************************************/
  112.  
  113. PROC    pp16Mono        _funct  numElements : _int, bufStart : _ptr, \
  114.                                 mixPos : _int, mixBuffer : _ptr, \
  115.                                 ppTable : _ptr
  116. USES _si,_di,_bx
  117.  
  118.         PUSHSEGREG ds
  119.  
  120.         LOADPTR es,_di,[bufStart]       ; point _esdi to destinatio buffer
  121.         add     _di,[mixPos]
  122.         LOADPTR ds,_si,[mixBuffer]      ; point _dssi to source buffer
  123.  
  124. IF 0    ; new clipping post-processing routine below!
  125.  
  126. IFDEF __16__
  127.         mov     cx,[numElements]        ; cx = number of elements
  128.         test    cx,cx
  129.         jz      @@done
  130.         shr     cx,1                    ; cx = number of dwords
  131.         cld
  132.         rep     movsd
  133. ELSE
  134.         mov     ecx,[numElements]
  135.         test    ecx,ecx
  136.         jz      @@done
  137.         shr     ecx,1                   ; two elements are done at a time
  138.  
  139.         mov     eax,ecx
  140.         and     eax,15
  141.  
  142.         shl     eax,2
  143.         neg     eax                     ; eax = jump table offset (64 - 4*eax)
  144.         add     eax,64
  145.  
  146.         sub     edi,eax                 ; undo edi incrementing in loop
  147.         mov     ebx,[pp16Jump+eax]      ; ebx = jump offset
  148.         shl     eax,1
  149.         sub     esi,eax                 ; undo edi incrementing in loop
  150.  
  151.         shr     ecx,4                   ; ecx = number of loops to mix
  152.         inc     ecx
  153.  
  154.         jmp     ebx
  155.  
  156.  
  157. @@loop:
  158. a = 0
  159. REPT 16
  160. NumLabel pp16, %a
  161.         mov     eax,[esi + 8*a + 4]
  162.         shl     eax,16
  163.         mov     ax,[word esi+8*a]
  164.         mov     [edi+4*a],eax
  165. a = a + 1
  166. ENDM
  167. NumLabel pp16, %a
  168.         add     edi,64
  169.         add     esi,128
  170.         dec     ecx
  171.         jnz     @@loop
  172.  
  173. ENDIF
  174.  
  175.  
  176. ENDIF   ; IF 0
  177.  
  178.         mov     ebx,[oldValue]
  179.         mov     ecx,[numElements]       ; ecx = number of elements, loop count
  180.         test    ecx,ecx
  181.         jz      @@done
  182.  
  183. @@loop:
  184.         mov     eax,[esi]
  185.         add     esi,4
  186.         cmp     eax,32767
  187.         jg      @@above
  188.         cmp     eax,-32768
  189.         jl      @@below
  190.  
  191. IF 0
  192.         mov     edx,eax
  193. ;        add     eax,edx
  194. ;        add     eax,edx
  195.         add     eax,ebx
  196.         sar     eax,1
  197.         mov     ebx,edx
  198. ENDIF
  199.  
  200.         mov     [edi],ax
  201.         add     edi,2
  202.         dec     ecx
  203.         jnz     @@loop
  204.         jmp     @@done
  205.  
  206. @@above:
  207.         mov     [word ptr edi],32767
  208.         mov     ebx,32767
  209.         add     edi,2
  210.         dec     ecx
  211.         jnz     @@loop
  212.         jmp     @@done
  213.  
  214. @@below:
  215.         mov     [word ptr edi],-32768
  216.         mov     ebx,-32768
  217.         add     edi,2
  218.         dec     ecx
  219.         jnz     @@loop
  220.  
  221.  
  222. @@done:
  223.         mov     [oldValue],ebx
  224.         sub     _di,[_int bufStart]     ; return new mixing position
  225.         mov     _ax,_di
  226.  
  227.         POPSEGREG ds
  228.  
  229.         ret
  230. ENDP
  231.  
  232.  
  233.  
  234.  
  235. LABEL   pp8Jump         _int
  236. JmpTable pp8, 17
  237.  
  238. ;/***************************************************************************\
  239. ;*
  240. ;* Function:    unsigned pp8Mono(unsigned numElements, uchar *bufStart,
  241. ;*                  unsigned mixPos, unsigned *mixBuffer, uchar *ppTable);
  242. ;*
  243. ;* Description: 8-bit mono post-processing routine
  244. ;*
  245. ;* Input:       unsigned numElements    number of elements to process
  246. ;*                                       (guaranteed to be even)
  247. ;*              uchar *bufStart         pointer to start of DMA buffer
  248. ;*              unsigned mixPos         mixing position in DMA buffer
  249. ;*              unsigned *mixBuffer     pointer to source mixing buffer
  250. ;*              uchar *ppTable          post-processing table
  251. ;*
  252. ;* Returns:     New mixing position in DMA buffer. Can not fail.
  253. ;*
  254. ;* (Could use some optimization)
  255. ;*
  256. ;\***************************************************************************/
  257.  
  258. PROC    pp8Mono         _funct  numElements : _int, bufStart : _ptr, \
  259.                                 mixPos : _int, mixBuffer : _ptr, \
  260.                                 ppTable : _ptr
  261. USES    _si,_di,_bx
  262.  
  263.         PUSHSEGREG ds
  264.  
  265. IFDEF __16__
  266.  
  267.         lds     si,[ppTable]            ; point ds:si to post-proc. table
  268.         LOADPTR es,_di,[bufStart]       ; point _esdi to destination buffer
  269.         add     _di,[mixPos]
  270.  
  271.         mov     _cx,[numElements]       ; number of elements to process
  272.         test    _cx,_cx
  273.         jz      @@done
  274.         shr     _cx,1                   ; number of destination words
  275.  
  276.         mov     bx,cx
  277.         and     bx,15
  278.  
  279.         shl     bx,1
  280.         neg     bx
  281.         add     bx,32                   ; undo di incrementing in loop
  282.         sub     di,bx
  283.         mov     ax,[pp8Jump+bx]         ; ax = jump offset
  284.  
  285.         push    bp
  286.         LOADPTR gs,_bp,[mixBuffer]      ; point gs:bp to source buffer
  287.  
  288.         shl     bx,1
  289.         sub     bp,bx                   ; undo bp incrementing in loop
  290.  
  291.         shr     cx,4                    ; cx = number of loops to do
  292.         inc     cx
  293.  
  294.         jmp     ax
  295.  
  296. @@loop:
  297. a = 0
  298. REPT 16
  299. NumLabel pp8, %a
  300.         mov     bx,[gs:bp+4*a]
  301.         mov     al,[si+bx+((1 SHL MIX8BITS)/2)]
  302.         mov     bx,[gs:bp+4*a+2]
  303.         mov     ah,[si+bx+((1 SHL MIX8BITS)/2)]
  304.         mov     [es:di+2*a],ax
  305. a = a + 1
  306. ENDM
  307. NumLabel pp8, %a
  308.         add     bp,64
  309.         add     di,32
  310.         dec     cx
  311.         jnz     @@loop
  312.  
  313.         pop     bp
  314. ELSE
  315.         LOADPTR ds,_si,[mixBuffer]      ; point _si to source buffer
  316.         LOADPTR es,_di,[bufStart]       ; point _esdi to destination buffer
  317.         add     _di,[mixPos]
  318.  
  319.         mov     _cx,[numElements]       ; number of elements to process
  320.         test    _cx,_cx
  321.         jz      @@done
  322.         shr     _cx,1                   ; number of destination words
  323.  
  324.  
  325.         mov     eax,ecx
  326.         and     eax,15
  327.  
  328.         shl     eax,1
  329.         neg     eax
  330.         add     eax,32                  ; undo edi incrementing in loop
  331.         sub     edi,eax
  332.  
  333.         shl     eax,1
  334.         mov     ebx,[pp8Jump+eax]       ; ebx = jump offset
  335.  
  336.         shl     eax,1
  337.         sub     esi,eax                 ; undo esi incrementing in loop
  338.  
  339.         shr     ecx,4                   ; ecx = number of loops to do
  340.         inc     ecx
  341.  
  342. ;        push    ebp
  343. ;        mov     ebp,[ppTable]           ; point ebp to post-proc. table
  344.         mov     edx,[ppTable]
  345.  
  346.         jmp     ebx
  347.  
  348. @@loop:
  349. a = 0
  350. REPT 16
  351. NumLabel pp8, %a
  352.         mov     ebx,[esi+8*a]
  353.         mov     al,[edx+ebx+((1 SHL MIX8BITS)/2)]
  354.         mov     ebx,[esi+8*a+4]
  355.         mov     ah,[edx+ebx+((1 SHL MIX8BITS)/2)]
  356.         mov     [edi+2*a],ax
  357. a = a + 1
  358. ENDM
  359. NumLabel pp8, %a
  360.         add     esi,128
  361.         add     edi,32
  362.         dec     ecx
  363.         jnz     @@loop
  364.  
  365. ;        pop     ebp
  366.  
  367. ENDIF
  368. @@done:
  369.         sub     _di,[_int bufStart]     ; return new mixing position
  370.         mov     _ax,_di
  371.  
  372.         POPSEGREG ds
  373.  
  374.         ret
  375. ENDP
  376.  
  377.  
  378.  
  379.  
  380. ;/***************************************************************************\
  381. ;*
  382. ;* Function:    unsigned pp16Stereo(unsigned numElements, uchar *bufStart,
  383. ;*                  unsigned mixPos, unsigned *mixBuffer, uchar *ppTable);
  384. ;*
  385. ;* Description: 16-bit stereo post-processing routine
  386. ;*
  387. ;* Input:       unsigned numElements    number of elements to process
  388. ;*                                       (guaranteed to be even)
  389. ;*              uchar *bufStart         pointer to start of DMA buffer
  390. ;*              unsigned mixPos         mixing position in DMA buffer
  391. ;*              unsigned *mixBuffer     pointer to source mixing buffer
  392. ;*              uchar *ppTable          post-processing table
  393. ;*
  394. ;* Returns:     New mixing position in DMA buffer. Can not fail.
  395. ;*
  396. ;\***************************************************************************/
  397.  
  398. PROC    pp16Stereo      _funct  numElements : _int, bufStart : _ptr, \
  399.                                 mixPos : _int, mixBuffer : _ptr, \
  400.                                 ppTable : _ptr
  401. USES _si,_di,_bx
  402.  
  403.         ; Since the mono post-processing routine does exactly what we need
  404.         ; to do here, why not as well use it?
  405.         mov     _ax,[numElements]
  406.         shl     _ax,1
  407.         call    pp16Mono LANG, _ax, [bufStart], [mixPos], [mixBuffer], \
  408.                 [ppTable]
  409.  
  410.         ret
  411. ENDP
  412.  
  413.  
  414.  
  415.  
  416. ;/***************************************************************************\
  417. ;*
  418. ;* Function:    unsigned pp8Stereo(unsigned numElements, uchar *bufStart,
  419. ;*                  unsigned mixPos, unsigned *mixBuffer, uchar *ppTable);
  420. ;*
  421. ;* Description: 8-bit stereo post-processing routine
  422. ;*
  423. ;* Input:       unsigned numElements    number of elements to process
  424. ;*                                       (guaranteed to be even)
  425. ;*              uchar *bufStart         pointer to start of DMA buffer
  426. ;*              unsigned mixPos         mixing position in DMA buffer
  427. ;*              unsigned *mixBuffer     pointer to source mixing buffer
  428. ;*              uchar *ppTable          post-processing table
  429. ;*
  430. ;* Returns:     New mixing position in DMA buffer. Can not fail.
  431. ;*
  432. ;* (Could use some optimization)
  433. ;*
  434. ;\***************************************************************************/
  435.  
  436. PROC    pp8Stereo       _funct  numElements : _int, bufStart : _ptr, \
  437.                                 mixPos : _int, mixBuffer : _ptr, \
  438.                                 ppTable : _ptr
  439. USES    _si,_di,_bx
  440.  
  441.         ; Since the mono post-processing routine does exactly what we need
  442.         ; to do here, why not as well use it?
  443.         mov     _ax,[numElements]
  444.         shl     _ax,1
  445.         call    pp8Mono LANG, _ax, [bufStart], [mixPos], [mixBuffer], \
  446.                 [ppTable]
  447.  
  448.         ret
  449. ENDP
  450.  
  451.  
  452. ;* $Log: postproc.asm,v $
  453. ;* Revision 1.3  1997/01/16 18:41:59  pekangas
  454. ;* Changed copyright messages to Housemarque
  455. ;*
  456. ;* Revision 1.2  1996/07/13 17:28:28  pekangas
  457. ;* Fixed to preserve ebx
  458. ;*
  459. ;* Revision 1.1  1996/05/22 21:00:30  pekangas
  460. ;* Initial revision
  461. ;*
  462. ;* Revision 1.1  1996/05/22 20:49:33  pekangas
  463. ;* Initial revision
  464. ;*
  465.  
  466.  
  467. END